package com.alphas.xixibackendalphas.once;

import com.alphas.xixibackendalphas.model.domain.User;
import com.alphas.xixibackendalphas.service.UserService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;
import java.util.ArrayList;

@Component
public class InsertUsers {
    @Resource
    private UserService userService;

    /**
     * 插入用户的定时任务
     */
//    @Scheduled(fixedDelay = 5000)
    public void doInsertUsers(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("insertUsers");
        final int INSERT_COUNT = 1000;
        ArrayList<User> list = new ArrayList<>();
        for (int i = 0; i < INSERT_COUNT; i++) {
            User user = new User();
            user.setUserName("fakeUser" + i);
            user.setUserAccount("fakeUser" + i);
            user.setAvatarUrl("");
            user.setGender(0);
            user.setUserPassword("12345678");
            user.setEmail("123@qq.com");
            user.setPhone("123");
            user.setUserStatus(0);
            user.setUserRole(0);
            user.setUserTags("");
            list.add(user);
        }
        userService.saveBatch(list);
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
    }

    public static void main(String[] args) {

    }
}
